import java.util.Random;
import java.util.Scanner;

public class GuessNumMethod1 {
    public static void main(String[] args) {
        Random random = new Random();//生成随机数
        int num = random.nextInt(100)+1;//生成1-100以内的随机数
         System.out.println("请输入要猜的数字:");
        while(true) {
            Scanner scanner = new Scanner(System.in);
            int guessnum = scanner.nextInt();//猜数字
            if (guessnum > num) {
                System.out.println("猜大了,请再次输入:");
            } else if (guessnum < num) {
                System.out.println("猜小了，请再次输入:");
            } else {
                System.out.println("猜对了");
                System.out.println("游戏结束.");
                break;//猜对后结束循环
            }
        }
    }

}
